package com.cn.lycss.service;

import com.cn.lycss.dao.NavDao;
import com.cn.lycss.model.NavModel;
import com.cn.lycss.util.IOTool;
import com.cn.lycss.util.Tool;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class INavModelService {
    String path = "D:\\spring-5.3.2-dist\\wanxi\\step3\\xueyuan03\\web\\note";
    String fileName = "company.txt";
    public List<NavModel> getNavModel() {
        IOTool.createFile(path,fileName);
        List<String> data= setNavData() ;
        IOTool.writeData(data);
        String string=IOTool.readData();
       List<NavModel> navModelList= setData(string);
        return navModelList;
    }

    private List<NavModel> setData(String string) {
        System.out.println(string);
//        NavModel[] navModels=new NavModel[6];
        String[] split=string.split(IOTool.SPLIT);
//        String href=split[0];
        String href = Tool.replace(split[0]);
        String title =Tool.replace(split[1]);
        String[] hrefs= href.split(",");
        String[] titles= title.split(",");
        List<NavModel> navModelList=new ArrayList<>();
        NavDao navDao=new NavDao();
        for (int i = 0; i <titles.length ; i++) {
            NavModel navModel=new NavModel();
            navModel.setHref(hrefs[i]);
            navModel.setTitle(titles[i]);
//            navModels[i] =navModel;
            navModelList.add(navModel);

        }
        return navModelList;
    }

    private List<String> setNavData() {
        NavDao dao=new NavDao();
        List<String> data=new ArrayList<>();
        StringBuilder stringBuilder=new StringBuilder();
        for (String aa:dao.href
        ) {
            stringBuilder.append(aa).append(",");
        }
        data.add(Arrays.toString(dao.href));
        data.add(Arrays.toString(dao.title));
        return data;
    }
}
